﻿using System;
using System.ComponentModel.DataAnnotations;
using XCI.Annotations;
using XCI.Core;

namespace XCI.Sys.Filter
{
    /// <summary>
    /// 历史日志过滤条件
    /// </summary>
    public class SysHistoryLogFilter : BasePageFilter
    {
        /// <summary>
        /// 默认过滤对象
        /// </summary>
        public static SysHistoryLogFilter Default { get; } = new SysHistoryLogFilter
        {
            Category = "1,2,3",
            OperateStartDateTime = DateTime.Now.Date.AddDays(-7),
            OperateEndDateTime = DateTime.Now.Date
        };

        /// <summary>
        /// 操作类型 [1-新建, 2-修改, 3-删除]
        /// </summary>
        [Display(Name = "操作类型")]
        public string Category { get; set; }

        /// <summary>
        /// 表名
        /// </summary>
        [Display(Name = "表名")]
        public string TableName { get; set; }

        /// <summary>
        /// 记录主键
        /// </summary>
        [Display(Name = "记录主键")]
        public string PrimaryKey { get; set; }

        /// <summary>
        /// 操作人姓名
        /// </summary>
        [Display(Name = "操作人姓名")]
        public string OperateUserName { get; set; }

        /// <summary>
        /// 操作开始时间
        /// </summary>
        [Display(Name = "开始时间")]
        public DateTime? OperateStartDateTime { get; set; }

        private DateTime? _operateEndDateTime;
        /// <summary>
        /// 操作结束时间
        /// </summary>
        [Display(Name = "结束时间")]
        [CompareDate(nameof(OperateStartDateTime), DateCompareType.GreatThan)]
        public DateTime? OperateEndDateTime
        {
            get => _operateEndDateTime;
            set => _operateEndDateTime = value?.AddDays(1);
        }
    }

    /// <summary>
    /// 错误日志过滤对象
    /// </summary>
    public class SysErrorLogFilter : BasePageFilter
    {
        /// <summary>
        /// 默认过滤对象
        /// </summary>
        public static SysOperateLogFilter Default { get; } = new SysOperateLogFilter
        {
            OperateStartDateTime = DateTime.Now.Date.AddDays(-7),
            OperateEndDateTime = DateTime.Now.Date
        };

        /// <summary>
        /// 请求地址
        /// </summary>
        [Display(Name = "请求地址")]
        public string ReqUrl { get; set; }

        /// <summary>
        /// 应用主键
        /// </summary>
        [Display(Name = "应用主键")]
        public string AppId { get; set; }

        /// <summary>
        /// 应用名称
        /// </summary>
        [Display(Name = "应用名称")]
        public string AppName { get; set; }

        /// <summary>
        /// IP地址
        /// </summary>
        [Display(Name = "IP地址")]
        public string Ip { get; set; }

        /// <summary>
        /// 操作人主键
        /// </summary>
        [Display(Name = "操作人主键")]
        public string OperateUserId { get; set; }

        /// <summary>
        /// 操作人姓名
        /// </summary>
        [Display(Name = "操作人姓名")]
        public string OperateUserName { get; set; }

        /// <summary>
        /// 操作开始时间
        /// </summary>
        [Display(Name = "开始时间")]
        public DateTime? OperateStartDateTime { get; set; }

        private DateTime? _operateEndDateTime;
        /// <summary>
        /// 操作结束时间
        /// </summary>
        [Display(Name = "结束时间")]
        [CompareDate(nameof(OperateStartDateTime), DateCompareType.GreatThan)]
        public DateTime? OperateEndDateTime
        {
            get => _operateEndDateTime;
            set => _operateEndDateTime = value?.AddDays(1);
        }
    }

    /// <summary>
    /// 系统定时任务日志过滤条件
    /// </summary>
    public class SysJobLogFilter : BasePageFilter
    {
        /// <summary>
        /// 默认过滤对象
        /// </summary>
        public static SysJobLogFilter Default { get; } = new SysJobLogFilter
        {
            OperateStartDateTime = DateTime.Now.Date.AddDays(-7),
            OperateEndDateTime = DateTime.Now.Date
        };

        /// <summary>
        /// 名称/编码关键字
        /// </summary>
        [Display(Name = "关键字")]
        public string Key { get; set; }

        /// <summary>
        /// 任务组
        /// </summary>
        [Display(Name = "任务组")]
        public string Category { get; set; }

        /// <summary>
        /// 状态 [true-启用, false-禁用]
        /// </summary>
        [Display(Name = "状态")]
        public bool? Status { get; set; }

        /// <summary>
        /// 操作开始时间
        /// </summary>
        [Display(Name = "开始时间")]
        public DateTime? OperateStartDateTime { get; set; }

        private DateTime? _operateEndDateTime;
        /// <summary>
        /// 操作结束时间
        /// </summary>
        [Display(Name = "结束时间")]
        [CompareDate(nameof(OperateStartDateTime), DateCompareType.GreatThan)]
        public DateTime? OperateEndDateTime
        {
            get => _operateEndDateTime;
            set => _operateEndDateTime = value?.AddDays(1);
        }
    }

    /// <summary>
    /// 系统登录日志过滤条件
    /// </summary>
    public class SysLoginLogFilter : IPageParam
    {
        /// <summary>
        /// 默认过滤对象
        /// </summary>
        public static SysLoginLogFilter Default { get; } = new SysLoginLogFilter
        {
            OperateStartDateTime = DateTime.Now.Date.AddDays(-7),
            OperateEndDateTime = DateTime.Now.Date
        };

        /// <summary>
        /// 登录类型 [1-登录, 2-注销]
        /// </summary>
        [Display(Name = "登录类型")]
        public string Category { get; set; }

        /// <summary>
        /// 用户主键
        /// </summary>
        [Display(Name = "用户主键")]
        public string UserId { get; set; }

        /// <summary>
        /// 用户姓名
        /// </summary>
        [Display(Name = "用户姓名")]
        public string UserName { get; set; }

        /// <summary>
        /// 用户账号
        /// </summary>
        [Display(Name = "用户账号")]
        public string UserAccount { get; set; }

        /// <summary>
        /// 登录地址
        /// </summary>
        [Display(Name = "登录地址")]
        public string Ip { get; set; }

        /// <summary>
        /// 登录状态 [true-成功, false-失败]
        /// </summary>
        [Display(Name = "登录状态")]
        public bool? Status { get; set; }

        /// <summary>
        /// 应用主键
        /// </summary>
        [Display(Name = "应用主键")]
        public string AppId { get; set; }

        /// <summary>
        /// 应用名称
        /// </summary>
        [Display(Name = "应用名称")]
        public string AppName { get; set; }

        /// <summary>
        /// 登录开始时间
        /// </summary>
        [Display(Name = "开始时间")]
        public DateTime? OperateStartDateTime { get; set; }

        private DateTime? _operateEndDateTime;
        /// <summary>
        /// 登录结束时间
        /// </summary>
        [Display(Name = "结束时间")]
        [CompareDate(nameof(OperateStartDateTime), DateCompareType.GreatThan)]
        public DateTime? OperateEndDateTime
        {
            get => _operateEndDateTime;
            set => _operateEndDateTime = value?.AddDays(1);
        }

        /// <summary>
        /// 分页过滤参数
        /// </summary>
        public BasePageFilter PageFilter { get; set; }
    }

    /// <summary>
    /// 操作日志过滤条件
    /// </summary>
    public class SysOperateLogFilter : BasePageFilter
    {
        /// <summary>
        /// 默认过滤对象
        /// </summary>
        public static SysOperateLogFilter Default { get; } = new SysOperateLogFilter
        {
            OperateStartDateTime = DateTime.Now.Date.AddDays(-7),
            OperateEndDateTime = DateTime.Now.Date
        };

        /// <summary>
        /// 模块
        /// </summary>
        [Display(Name = "模块")]
        public string Module { get; set; }

        /// <summary>
        /// 请求地址
        /// </summary>
        [Display(Name = "请求地址")]
        public string ReqUrl { get; set; }

        /// <summary>
        /// 操作方法
        /// </summary>
        [Display(Name = "操作方法")]
        public string ExecuteMethod { get; set; }

        /// <summary>
        /// 应用主键
        /// </summary>
        [Display(Name = "应用主键")]
        public string AppId { get; set; }

        /// <summary>
        /// 应用名称
        /// </summary>
        [Display(Name = "应用名称")]
        public string AppName { get; set; }

        /// <summary>
        /// IP地址
        /// </summary>
        [Display(Name = "IP地址")]
        public string Ip { get; set; }

        /// <summary>
        /// 操作状态 [true-成功, false-失败]
        /// </summary>
        [Display(Name = "操作状态")]
        public bool? Status { get; set; }

        /// <summary>
        /// 操作人姓名ID
        /// </summary>
        public string OperateUserId { get; set; }

        /// <summary>
        /// 操作人姓名
        /// </summary>
        public string OperateUserName { get; set; }

        /// <summary>
        /// 操作开始时间
        /// </summary>
        [Display(Name = "开始时间")]
        public DateTime? OperateStartDateTime { get; set; }

        private DateTime? _operateEndDateTime;
        /// <summary>
        /// 操作结束时间
        /// </summary>
        [Display(Name = "结束时间")]
        [CompareDate(nameof(OperateStartDateTime), DateCompareType.GreatThan)]
        public DateTime? OperateEndDateTime
        {
            get => _operateEndDateTime;
            set => _operateEndDateTime = value?.AddDays(1);
        }
    }
}
